/* **********************************************************************************
*
* Copyright (c) Microsoft Corporation. All rights reserved.
*
* This source code is subject to terms and conditions of the Shared Source License
* for DSL Editor PowerToy. A copy of the license can be found in the License.htm file
* at the root of this distribution. If you can not locate the Shared Source License
* for DSL Editor PowerToy, please obtain a copy from: http://www.codeplex.com/dsltreegrideditor/Project/License.aspx.
* By using this source code in any fashion, you are agreeing to be bound by
* the terms of the Shared Source License for DSL Editor PowerToy.
*
* You must not remove this notice, or any other, from this software.
*
* **********************************************************************************/
using System;
using System.ComponentModel;


namespace DslEditorPowerToy.ComponentModel.Design
{
    /// <summary>
    /// Editor that returns the path (rooted at solution) of the selected solution item
    /// </summary>
    public class SolutionItemPathPickerEditor : SolutionItemPickerEditor
    {
        #region Public Methods
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            //Get selected item
            object selectedItem = base.EditValue(context, provider, value);
            if (null != selectedItem)
            {
                //Solution is root path
                if (selectedItem is EnvDTE.Solution)
                    return String.Empty;

                //Return solution rooted path
                return Microsoft.Practices.RecipeFramework.Library.DteHelper.BuildPath(selectedItem);
            }

            return string.Empty;
        }
        #endregion
    }
}
